from flask import Flask
from setting import *
from flask_session import Session
from ext import db, cache, cors

# 导入蓝图
from apps.views.user import user_bp
from apps.views.accessory import accessory_bp
from apps.views.book import book_bp

def create_app():

    app = Flask(__name__, template_folder="../templates",
                static_folder="../static")

    # 数据库配置与初始化
    app.config.from_object(ProductionConfig)
    db.init_app(app)

    # 初始化session、跨域与cache
    Session(app)
    cache.init_app(app=app, config=cache_config)
    cors.init_app(app=app, supports_credentials=True)

    # 注册蓝图
    app.register_blueprint(user_bp)
    app.register_blueprint(accessory_bp)
    app.register_blueprint(book_bp)

    return app